package com.study.design.model.behaviorPattern.observer.j2se;

import org.junit.Test;

/**
* @Name: Client
* @Description: 观察者模式测试客户端
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-15 下午10:11:37 
* @Version: V1.0
 */
public class Client {
	
	@Test
	public void observer() {
		//目标对象
		ConcreteSubject subject = new ConcreteSubject() ;
		//创建多个观察者
		MyObserver obs01 = new MyObserver() ;
		MyObserver obs02 = new MyObserver() ;
		MyObserver obs03 = new MyObserver() ;
		//将这三个观察者添加到目标对象的观察者队伍中去
		subject.addObserver(obs01) ;
		subject.addObserver(obs02) ;
		subject.addObserver(obs03) ;
		//改变主题状态
		subject.set(300) ;
		//查看观察者的状态
		System.out.println("############################");
		System.out.println(obs01.getMyState());
		System.out.println(obs02.getMyState());
		System.out.println(obs03.getMyState());
		//改变主题状态
		subject.set(30) ;
		//查看观察者的状态
		System.out.println("############################");
		System.out.println(obs01.getMyState());
		System.out.println(obs02.getMyState());
		System.out.println(obs03.getMyState());
	}

}
